<?php

namespace App\Http\Controllers\Home;

use App\Models\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Gregwar\Captcha\CaptchaBuilder;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;

// namespace App\Http\Controllers\home;

// use Illuminate\Http\Request;
// use App\Http\Controllers\Controller;

// use DB;

class RegisterController extends Controller
{
    public function Index()
    {
    	return view('home.register');
    }

     public function store(Requests\RegisterRequest $request)
    {
        // dd($request);
        $user = new User();
        $data = $request->only('username','password','email','pic','');
        $user->password = Hash::make($data['password']);
        $user->status = 1;
        $user->level = 0;
        $user->username = $data['username'];
        $user->email = $data['email'];
        $user->pic = $data['pic'];

        if($user->save()){
            return redirect('/login');
        }else{
            return back()->with('error','添加失败');
        }

        // dd($request);
        // $data = $request->except('_tken','Submit','confirm_password');
        // $list = DB::table('users')->insertGetId($data);

        // if($user>0){
        //     return redirect('/login');
        // }else{
        //     return back()->with('error','添加失败');
        // }


    }
}
